﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Text;

namespace Honestysoft.Financing.WebUI.Module.Audit.JSON
{
    /// <summary>
    /// GetProjectBySN 的摘要说明
    /// </summary>
    public class GetProjectBySN : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string responseData = "";
            string sn = context.Request.Params["SN"];
            Honestysoft.Financing.BusinessLogic.Project bll = new BusinessLogic.Project("");
            DataTable dt = bll.GetProjectBySN(sn);
            if (dt == null || dt.Rows.Count == 0)
            {
                responseData = "-1";
            }
            else
            {
                if (dt.Rows.Count == 1)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append("[");
                    sb.Append("{");
                    sb.AppendFormat("\"id\":\"{0}\",", dt.Rows[0]["ID"].ToString());
                    sb.AppendFormat("\"sn\":\"{0}\",", dt.Rows[0]["SN"].ToString());
                    sb.AppendFormat("\"name\":\"{0}\",", dt.Rows[0]["Name"].ToString());
                    sb.AppendFormat("\"ownerName\":\"{0}\"", dt.Rows[0]["OwnerName"].ToString());
                    sb.Append("}");
                    sb.Append("]");
                    responseData = sb.ToString();
                }
                else
                {
                    responseData = "0";
                }
            }
            context.Response.Write(responseData);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}